package com.iflytek.tts.TtsService;

import android.media.AudioTrack;
import android.util.Log;

public class AudioData
{
  private static final String TAG = "TtsService(audio)";
  private static AudioTrack mAudio = null;
  private static int mBuffSize;
  public static int mCurrentPosition;
  private static int mSampleRate;
  private static int mStreamType = 3;
  
  static
  {
    mSampleRate = 16000;
    mBuffSize = 8000;
    mCurrentPosition = 0;
    mAudio = new AudioTrack(mStreamType, mSampleRate, 2, 2, mBuffSize, 1);
    Log.d(TAG, " AudioTrack create ok");
  }
  
  public static void onJniOutData(int paramInt, byte[] paramArrayOfByte)
  {
    if (mAudio == null)
    {
      Log.e(TAG, " mAudio null");
      return;
    }
    if (mAudio.getState() != 1)
    {
      Log.e(TAG, " mAudio STATE_INITIALIZED");
      return;
    }
    try
    {
      mAudio.write(paramArrayOfByte, 0, paramInt);
      mAudio.play();
    }
    catch (Exception ex)
    {
      Log.e(TAG, ex.toString());
    }
  }
  
  public static void onJniWatchCB(int paramInt)
  {
    Log.d(TAG, "onJniWatchCB  process begin = " + paramInt);
    mCurrentPosition = paramInt / 2;
  }
}
